package com.imooc.scala.log

import org.apache.spark.sql.SparkSession

object SparkStatFormat {
  //1.
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder().appName("stat").master("local[*]").getOrCreate()
    val log = spark.sparkContext.textFile("access.log")
    //    log.take(20).foreach(println)

    log.map(line => {
      val lines = line.split(" ")
      val ip = lines(0)
      val time = lines(3) + " " + lines(4)
      val url = lines(6).replaceAll("\"", "")
      val traffic = lines(9)
      DateUtils.parse(time) + "\t" + url + "\t" + traffic + "\t" + ip
//    }).take(20).foreach(println)
        }).saveAsTextFile("nginx_log")
  }

}
